import javax.imageio.IIOException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class eg10_2 {
    public static void main(String[] args) {
        File helloFile = new File("f://","HelloWorld.txt");
                try{
                    //创建文件
                    boolean isCraeted = helloFile.createNewFile();
                    if (isCraeted || helloFile.exists()){
                        //以字节流方式写入文件helloFile
                        FileOutputStream out = new FileOutputStream(helloFile);
                        byte[] b  = "Java面向对象程序设计教程".getBytes();
                        out.write(b,0,b.length);
                        out.close();
                        //以字节流方式读出文件helloFile
                        FileInputStream in = new FileInputStream(helloFile);
                        int end;
                        while ((end  = in.read(b,0,b.length)) != -1){
                            String s = new String(b,0,end);
                            System.out.println(s);
                        }
                        in.close();
                    }
                }catch (IOException ex){
                    Logger.getLogger(eg10_2.class.getName()).log(Level.SEVERE,null,ex);
                }
    }
}
